package com.geetour.columbus.region.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geetour.columbus.common.exceptions.BOException;
import com.geetour.columbus.common.model.R.CityPage;
import com.geetour.columbus.region.bo.ICityPageBO;
import com.geetour.columbus.region.dao.ICityPageDAO;

@Service
public class CityPageBOImpl implements ICityPageBO {

    private ICityPageDAO cityPageDAOImpl;

    @Autowired
    public void setCityPageDAOImpl(ICityPageDAO cityPageDAOImpl) {
        this.cityPageDAOImpl = cityPageDAOImpl;
    }

    @Override
    public void insertCityPage(CityPage city) throws BOException {
        if (city == null) {
            return;
        }
        cityPageDAOImpl.insertCityPage(city);
    }

    @Override
    public int insertCityPageBatch(List<CityPage> cityList) throws BOException {
        if (cityList == null || cityList.isEmpty()) {
            return -1;
        }
        return cityPageDAOImpl.insertCityPageBatch(cityList);
    }

    @Override
    public int updateCityPage(CityPage city) throws BOException {
        if (city == null) {
            return -1;
        }
        return cityPageDAOImpl.updateCityPage(city);
    }

    @Override
    public int deleteCityPage(Long id) throws BOException {
        if (id == null) {
            return -1;
        }
        return cityPageDAOImpl.deleteCityPage(id);
    }

    @Override
    public CityPage findCityPageById(Long id) throws BOException {
        if (id == null) {
            return null;
        }
        return cityPageDAOImpl.findCityPageById(id);
    }

    @Override
    public CityPage findCityPageByName(String name) throws BOException {
        if (name == null) {
            return null;
        }
        CityPage city = new CityPage();
        city.setName(name);
        List<CityPage> list = cityPageDAOImpl.findCityPages(city);
        if (list == null || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public List<CityPage> findAllCityPages() throws BOException {
        return cityPageDAOImpl.findAllCityPages();
    }

    @Override
    public List<CityPage> findCityPages(CityPage city) throws BOException {
        if (city == null) {
            return null;
        }
        return cityPageDAOImpl.findCityPages(city);
    }

}
